<xsl:stylesheet version = '1.0'
    xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
    xmlns:cfd='http://www.sat.gob.mx/cfd/2'>
<xsl:import href="cadenaoriginal.xsl"/>

<xsl:output method = "html" /> 
 
<xsl:template match="//cfd:Comprobante">
   <html>
   <head>
   <link rel="STYLESHEET" media="screen" type="text/css" href="factura.css"/>
   <title>Factura Electronica <xsl:value-of select="@serie"/><xsl:value-of select="@folio"/></title>
   </head>
   <body>
   	<table width="100%" border="0">
      <tr>	
      	<td width="50%">
      	</td>
      	<td width="50%" align="right">
          		<table border="1" align="center">
               	<tr>
               		<th class="h1">Serie</th><td class="h1"><xsl:value-of select="@serie"/></td>
               	</tr>
               	<tr>
               		<th class="h1">Folio</th><td class="h1"><xsl:value-of select="@folio"/></td>
               	</tr>
               	<tr>
               		<th class="h1">Fecha</th><td class="h1"><xsl:value-of select="@fecha"/></td>
               	</tr>
               	<tr>
               		<th class="h1">Aprobacion</th><td class="h1"><xsl:value-of select="@noAprobacion"/></td>
               	</tr>
           		</table>
           	</td>
      </tr>
      <tr>
      	<td width="50%">
           		<table width="100%" border="1">
           		<tr>
           			<th colspan="2" class="h1">Emisor<span class="blanco">XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</span></th>
           		</tr>
               	<tr>
               		<th>RFC</th>
               		<td><xsl:value-of select="cfd:Emisor/@rfc"/></td>
               	</tr>
               	<tr>
               		<th>Nombre</th>
               		<td><xsl:value-of select="cfd:Emisor/@nombre"/></td>
               	</tr>
                	<xsl:apply-templates select="//cfd:DomicilioFiscal"/>
              	</table>
          	</td>
          	<td width="50%">
          		<table width="100%" border="1">
          		<tr>
          			<th colspan="2" class="h1">Receptor<span class="blanco">XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</span></th>
          		</tr>
             	<tr>
             		<th>RFC</th><td><xsl:value-of select="cfd:Receptor/@rfc"/></td>
             	</tr>
             	<tr>
             		<th>Nombre</th><td><xsl:value-of select="cfd:Receptor/@nombre"/></td>
             	</tr>
             	<xsl:apply-templates select="//cfd:Domicilio"/>
 
           		</table>
           </td>
      </tr>
      <tr>
      	<td colspan="2">
         		<table width="100%" border="1">
             	<tr>
             		<th>Cantidad</th>
                 		<th>Descripcion<span class="blanco2">XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX	</span></th>
                 		<th>Precio<span class="blanco2">XXXX</span></th>
                 		<th>Importe</th>
             	</tr>
             	<xsl:apply-templates select="//cfd:Concepto"/>
             		<xsl:for-each select="Concepto">
             	</xsl:for-each>
              	<tr>
              		<td colspan="2"/>
                 		<td align="right">Subtotal</td>
		 		<xsl:choose>
		 			<xsl:when test="@version='1.0'">
		   				<td align="right"><span class="blanco3">XX</span><xsl:value-of select="sum(Conceptos/Concepto/@importe)"/></td>
		 			</xsl:when>
		 			<xsl:when test="@version='2.0'">
                   			<td align="right"><span class="blanco3">XX</span><xsl:value-of select="format-number(@subTotal, '###,###.00')"/></td>
		 			</xsl:when>
		 		</xsl:choose>
             	</tr>
	     		<xsl:if test="@version='2.0'">
             	<tr>
             		<td colspan="2"/>
                 		<td align="right">- Descuento</td>
	                 	<xsl:if test="@descuento"><span class="blanco3">XX</span><td align="right"><xsl:value-of select="format-number(@descuento, '###,##0.00')"/></td></xsl:if>
		 		<xsl:if test="not(@descuento)"><td align="right"><xsl:value-of select="0.0"/></td></xsl:if>
             	</tr>

	     		<tr>
	     			<td colspan="2"/>
                 		<td align="right">Subtotal</td>
                 		<xsl:if test="@descuento"><td align="right"><xsl:value-of select="format-number((@subTotal)- @descuento, '###,###.00')"/></td></xsl:if>
		 		<xsl:if test="not(@descuento)"><td align="right"><xsl:value-of select="@subTotal"/></td></xsl:if>
             	</tr>

              	</xsl:if>

             	<xsl:if test="@version='1.0'">
	        	<tr>
	        		<td colspan="2"/>
                 		<td align="right">Impuestos v1</td>
                 		<td align="right"><xsl:value-of select="sum(Impuestos/Retenciones/Retencion/@importe)+sum(Impuestos/Traslados/Traslado/@importe)"/></td>
                	</tr>
	      	</xsl:if>

               	<xsl:apply-templates select="//cfd:Traslado"/>
	     		<tr>
	     			<td colspan="2"/>
  	         		<td align="right">Total</td>
		 		<xsl:choose>
		   			<xsl:when test="@version='1.0'">
                    			<td align="right"><xsl:value-of select="sum(Conceptos/Concepto/@importe)+sum(Impuestos/Retenciones/Retencion/@importe)+sum(Impuestos/Traslados/Traslado/@importe)"/></td>
				   	</xsl:when>
		   			<xsl:when test="@version='2.0'">
                      			<td align="right"><xsl:value-of select="format-number(@total, '###,###.00')"/></td>
		   			</xsl:when>
		 		</xsl:choose>
             	</tr>
            	</table>
            </td>
         </tr>
         <tr>
         	<td colspan="2">
         		<table width="100%" border="1" align="left">
            	<tr>
            		<th>Numero de serie del Certificado</th>
            	</tr>
            	<tr>
            		<td><xsl:value-of select="@noCertificado"/></td>
            	</tr>
            	<tr>
            		<th>Cadena Original</th>
            	</tr>
            	<tr>
            		<td> <xsl:apply-imports/> </td>
            	</tr>
            	<tr>
            		<th>Sello Digital</th>
            	</tr>
            	<tr>
            		<td class="sello"><small><xsl:value-of select="@sello"/></small></td>
            	</tr>
        		</table>
        		<div align="center">
        			Este documento es una impresion de un comprobante fiscal digital
        		</div>
        	</td>
         </tr>
        </table>

    </body>
    </html>
</xsl:template>
 
 
<xsl:template match="//cfd:DomicilioFiscal">
    <tr><th colspan="2" class="h2">Domicilio</th></tr>
    <tr><td colspan="2"><xsl:value-of select="@calle"/> # <xsl:value-of select="@noExterior"/> - <xsl:value-of select="@noInterior"/></td></tr>
    <tr><td colspan="2"><xsl:value-of select="@colonia"/></td></tr>
    <tr><td colspan="2"><xsl:value-of select="@localidad"/></td></tr>
    <tr><td colspan="2"><xsl:value-of select="@referencia"/></td></tr>
    <tr><td colspan="2"><xsl:value-of select="@municipio"/>
    <xsl:if test="@codigoPostal"> CODIGO POSTAL <xsl:value-of select="@codigoPostal"/></xsl:if>
         </td></tr>
     <tr><td colspan="2"><xsl:value-of select="@estado"/></td></tr>
     <tr><td colspan="2"><xsl:value-of select="@pais"/></td></tr>
</xsl:template>
 
<xsl:template match="//cfd:Domicilio">
    <tr><th colspan="2" class="h2">Domicilio</th></tr>
    <tr><td colspan="2"><xsl:value-of select="@calle"/> # <xsl:value-of select="@noExterior"/> - <xsl:value-of select="@noInterior"/></td></tr>
    <tr><td colspan="2"><xsl:value-of select="@colonia"/></td></tr>
    <tr><td colspan="2"><xsl:value-of select="@localidad"/></td></tr>
    <tr><td colspan="2"><xsl:value-of select="@referencia"/></td></tr>
    <tr><td colspan="2"><xsl:value-of select="@municipio"/>
        <xsl:if test="@codigoPostal"> CODIGO POSTAL <xsl:value-of select="@codigoPostal"/></xsl:if>
        </td></tr>
    <tr><td colspan="2"><xsl:value-of select="@estado"/></td></tr>
    <tr><td colspan="2"><xsl:value-of select="@pais"/></td></tr>
</xsl:template>
 
<xsl:template match="//cfd:Concepto">
    <tr><td align="center"><span class="blanco3">XX</span><xsl:value-of select="@cantidad"/></td>
        <td><xsl:value-of select="@descripcion"/>
              <xsl:if test="cfd:InformacionAduanera"> -->> Pedimento=<xsl:value-of select="cfd:InformacionAduanera/@numero"/> Fecha=<xsl:value-of select="cfd:InformacionAduanera/@fecha"/> Aduana=<xsl:value-of select="cfd:InformacionAduanera/@aduana"/></xsl:if>
        </td>
        <td align="right"><span class="blanco3">XX</span><xsl:value-of select="@valorUnitario"/></td>
        <td align="right"><xsl:value-of select="format-number(@importe, '###,###.00')"/></td>
    </tr>
    <xsl:comment><xsl:if test="cfd:InformacionAduanera">
        <tr><td align="center">.</td>
        <td>Pedimento=<xsl:value-of select="cfd:InformacionAduanera/@numero"/> Fecha=<xsl:value-of select="cfd:InformacionAduanera/@fecha"/> Aduana=<xsl:value-of select="cfd:InformacionAduanera/@aduana"/></td>
        <td align="right">.</td>
        <td align="right">.</td>
    </tr>
    </xsl:if>    </xsl:comment>
</xsl:template>
 
<xsl:template match="//cfd:Traslado">
    <tr><td colspan="2" align="right"></td>
        <td align="right"><xsl:value-of select="@impuesto"/> (<xsl:value-of select="@tasa"/> %)</td>
        <td align="right"><xsl:value-of select="format-number(@importe, '###,###.00')"/></td>
    </tr>
</xsl:template>
 
</xsl:stylesheet>

